#pragma once
#include <vector>
#include "FindTextDialog.h"
 
class FindHelper
{
	ByteVector mBytesAbove;
	ByteVector mBytesBelow;
	WhatCharactersVector mWhatCharactersVector;

	ByteVector mWhats[SearchKind::kTotalCount];
	const BYTE* mRangeStart;
	const BYTE* mRangeEnd;
	int mLengthForSavedBytes;
	int mSearchKind;
public:
	FindHelper();
	~FindHelper();

	bool SetWhatVector(const WhatCharactersVector&);

	//bool SetSearchString(LPCTSTR, int searchKind);

	void SetRange(const BYTE* startPtr, const BYTE* endPtr);
	bool SearchDown(int& outIndexBegin, int& outIndexEnd);
	bool SearchUp(int& outIndexBegin, int& outIndexEnd);

private:
	bool FindDownFirstSequence(int& ioIndex);
	bool FindDownAnyOfTwoFirstSequences(int& ioBeginIndex, int& outEndIndex);
	bool ConfirmMatch(int& ioIndex) const;
	bool MatchWordAtIndex(const ByteVector& word, int index) const;

	bool FindUpFirstSequence(int& index);
	bool FindUpAnyOfTwoFirstSequences(int& ioBeginIndex, int& outEndIndex);


	void ReadHexDigits();

	bool SearchStringDown(const ByteVector&, int& outIndexBegin, int& outIndexEnd);
	bool SearchStringUp(const ByteVector&, int& outIndexBegin, int& outIndexEnd);
	bool SearchAllDown(int& outIndexBegin, int& outIndexEnd, int& outSearchKind);
	bool SearchAllUp(int& outIndexBegin, int& outIndexEnd, int& outSearchKind);
};

